package cn.vastbase.jdbc.base;

import org.junit.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * <p> 连接示例 </p>
 * <p>适用于Vastbase G100 2.2 Build 15.4 </p>
 */
public class ConnTestCase {

    static Connection conn = null;
    static String cname = "org.postgresql.Driver";
//    static String url = "jdbc:postgresql://172.16.55.175:6666/zxsdb?loggerLevel=OFF";
//    static String username = "zxs";
//    static String passwd = "Vastdata#0730";

    static String url = "jdbc:postgresql://172.16.55.187:8000/vastbase";
    static String username = "u2";
    static String passwd = "root@123";

    @Test
    public void connect() {
        try {
            Class.forName(cname);
            conn = DriverManager.getConnection(url, username, passwd);
            System.out.println("[SUCCESS] conn database success.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void connectWithLog() {
        try {
            Class.forName(cname);
            url += "?loggerLevel=trace&loggerFile=D:\\jdbc.log";
            conn = DriverManager.getConnection(url, username, passwd);
            System.out.println("[SUCCESS] conn database success.");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void disConn(Connection conn) throws SQLException {
        if (conn != null) {
            conn.close();
        }
    }
}
